package Day14.encapsulation;

import java.util.Scanner;

/**
 * @author HYHwtx
 * @version 1.0
 * @date 2022/2/21 11:44
 */

public class Account {
    private String name;//姓名
    private double lastMoney;//余额
    private String pwd;//密码

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length()>=2&&name.length()<=4){
            System.out.println("你输入的姓名符合格式");
            this.name = name;
        }else {
            System.out.println("你输入的姓名不符合要求，请重试！");
            this.name = "错误姓名。";

        }
    }


    public double getLastMoney() {

        return lastMoney;
    }

    public void setLastMoney(double lastMoney) {
       if (lastMoney> 20.0){
           this.lastMoney = lastMoney;
       }else {
           System.out.println("您输入余额格式不符合要求，余额必须大于20，默认取0");
           this.lastMoney =0;
       }
    }

    public String getPwd() {

        return pwd;
    }

    public void setPwd(String pwd) {
        if (pwd.length()>=6){
            this.pwd=pwd;
        }else {
            System.out.println("密码输入格式为6位，默认密码是123456");
            this.pwd = "123456";
        }
    }
   public Account(){

   }
   public Account(String name,double lastMoney,String pwd){
       this.setName(name);
       this.setLastMoney(lastMoney);
       this.setPwd(pwd);
   }
public void showInfo(){
    Scanner in = new Scanner(System.in);
    System.out.println("请输入密码：");
    int key = in.nextInt();
    if (key==123456){
        System.out.println("账户信息："+name+"，余额是："+lastMoney+"，密码是："+pwd);

    }else {
        System.out.println("您不是该账户所有者，您无权查看！");
    }
}


}

